<?php
/**
 * Created by PhpStorm.
 * User: 68008000
 * Date: 2017/11/30
 * Time: 17:13
 */

namespace app\common\model;


use think\Model;

/**
 * Class Order
 * @package app\common\model
 * 前台地址控制器
 */
class Order extends Model
{
    //连接数据库
    protected $table= 'shop_receiving_address';
    protected $pk= 'raid';
    //主页
    public function index(){

    }
    //添加地址
    public function address($data)
    {
        $raid = input('post.raid');
        if (isset($raid)) {
            //添加
            $data['address'] = implode(',', $data['address']);

            $Order = new Order();
            $result = $Order->validate(
                [
                    'raname' => 'require',
                    'address' => 'require',
//                'particular' => 'require',
//                'particulars' => 'require',
//                'phone' => 'request',
                ],
                [
                    'raname.require' => '请填写收货人',
                    'addressp.require' => '请填写地址',
                ]
            )->save($data,['raid' => $raid]);
            if (false === $result) {
                // 验证失败 输出错误信息
                dump($Order->getError());
            }
        } else {
            //添加
            $data['address'] = implode(',', $data['address']);

            $Order = new Order();
            $result = $Order->validate(
                [
                    'raname' => 'require',
                    'address' => 'require',
//                'particular' => 'require',
//                'particulars' => 'require',
//                'phone' => 'request',
                ],
                [
                    'raname.require' => '请填写收货人',
                    'addressp.require' => '请填写地址',
                ]
            )->save($data);
            if (false === $result) {
                // 验证失败 输出错误信息
                dump($Order->getError());
            }
        }
    }
    //添加订单
    public function add($data){
        $order = new OrderList([
            'pquantity'  => $data['pquantity'],
            'sprice' => $data['sprice'],
            'remark' => $data['remark'],
            'gid' => $data['gid'],
        ]);
        $order->save();

        $orders = new Orders([
            'onumber'  => $data['kk'],
            'tprice' => $data['sprice'],
            'remarks' => $data['remark'],
            'gid' => $data['gid'],
        ]);
        $orders->save();
    }
}